# 全局变量


a = 1200

def sum(a,b):
    return a+b

b = sum(10,20)
print(a+b)
print(sum(10,20))


# 1230
# 30


def f1(a,b,c):
    print(a,b,c)

    print(locals())  # 局部变量
    print("*" * 29)
    print(globals()) # 全局变量

f1(10,20,30)
# 10 20 30
# {'a': 10, 'b': 20, 'c': 30}
# {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x0000028474D271D0>, '__spec__': None, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'D:\\WorkProjectPython\\python-project01\\code04\\index06.py', '__cached__': None, 'a': 1200, 'sum': <function sum at 0x0000028474D371C0>, 'b': 30, 'f1': <function f1 at 0x0000028474DA7270>}
while True:
  a = input("请输入一个字符（输入Q或q结束）")
  if a.upper()=='Q':
    print("循环结束，退出")
    break
  else:
    print(a)


empNum = 0
salarySum= 0
salarys = []
while True:
  s = input("请输入员工的薪资（按Q或q结束）")
  if s.upper()=='Q':
    print("录入结束")
    break
  if float(s)<0:
    print("无效！继续录入！")
    continue
  print("录入成功！")
  empNum +=1
  salarys.append(float(s))
  salarySum += float(s)
print("员工数{0}".format(empNum))
print("录入薪资：",salarys)
print("总发薪资：",salarySum)
print("平均薪资{0}".format(salarySum/empNum))


#循环代码优化测试
import time
start = time.time()
for i in range(1000):
  result = []
  for m in range(10000):
    c = i * 1000      #提到外部循环
    #result = result + [m * 100] #不使用拼接,会产生大量新对象
    result.append(c+m*100)
end = time.time()
print("耗时：{0}".format((end-start)))

print("简单循环优化后...")
start2 = time.time()
for i in range(1000):
  result = []
  c = i*1000
  for m in range(10000):
    result.append(c+m*100)

end2 = time.time()
print("耗时：{0}".format((end2-start2)))
